package com.tshopping.dao;

import com.tshopping.bean.GoodsCollection;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface GoodsCollectionDao {

    @Insert("insert into goods_collection(user,goods,time) values(#{user},#{goods},#{time})")
    boolean insertGoodsCollection(@Param("user") int user, @Param("goods") int goods, @Param("time") String time);

    @Delete("delete from goods_collection where id=#{id}")
    boolean deleteGoodsCollectionById(@Param("id") int id);

    @Select("select * from goods_collection where user = #{user} limit #{start},#{size}")
    ArrayList<GoodsCollection> selectGoodsCollectionsByUserId(@Param("user") int user, @Param("start") int start, @Param("size") int size);

    @Select("select count(*) from goods_collection where goods=#{goods} and user=#{user}")
    int selectCountByGoodsAndUser(@Param("goods") int goods,@Param("user") int user);

    @Select("select count(*) from goods_collection where user =#{user}")
    int selectCountByUserId(@Param("user") int user);

    @Delete("delete from goods_collection where user=#{user} and goods=#{goods}")
    boolean deleteGoodsCollectionByUserAndGoods(@Param("user") int user,@Param("goods") int goods);
}
